require 'basecamp.rb'
require 'offline_basecamp_wrapper.rb'

class BasecampWrapper
  
  def self.create_wrapper(mode=:offline)
    if mode == :offline then
      OfflineBasecampWrapper.new
    else
      BasecampWrapper.new
    end
  end
  
  def initialize
    @connected = false
  end
  
  def connect!(params)
    @basecamp = Basecamp.new(params[:url], params[:username], params[:password])
    begin
      @basecamp.projects
      @connected = true
    rescue
      @connected = false
    end
  end
  
  def connected?
    @connected
  end
  
  def projects
    validate
    @basecamp.projects    
  end
  
  def milestones(project_id, find="all")
    validate
    @basecamp.milestones(project_id, find)
  end
      
  private
  def validate
    unless connected?
      raise "You are not connected to basecamp."
    end
  end
end